package com.arch.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**
 * @author pizhihui
 * @date 2024-06-03 10:03
 */
public class AppendFileDemo {


    public static void main(String[] args) throws IOException {

        System.setProperty("HADOOP_USER_NAME", "biadmin");

        Configuration conf = new Configuration();
        conf.addResource("core-site.xml");
        conf.addResource("hdfs-site.xml");

        FileSystem fs = FileSystem.get(conf);

        Path path = new Path("/tmp/data/res.txt");
        // FSDataOutputStream fsDataOutputStream = fs.create(path);

        // 写入空文件
//        boolean newFile = fs.createNewFile(path);
//        System.out.println(newFile);

        // 打开已有文件,追加写入内容
        FSDataOutputStream output = fs.append(path);


        output.writeBytes("hell world");


        output.flush();

        // 关闭
        output.close();
        fs.close();




    }

}
